home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / std / c++ / 819 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  1.9 KB

  1. From: clamage@Eng.Sun.COM (Steve Clamage)
  2. Message-ID: <4isusi$flo@engnews1.Eng.Sun.COM>
  3. X-Original-Date: 22 Mar 1996 01:13:54 GMT
  4. Path: in1.uu.net!bounce-back
  5. Date: 22 Mar 96 02:24:21 GMT
  6. Approved: fjh@cs.mu.oz.au
  7. Newsgroups: comp.std.c++
  8. Subject: Re: Q : dynamic_cast<>()
  9. Organization: Sun Microsystems Inc.
  10. References: <199603211714.RAA26760@florin.msk.su>
  11. Reply-To: clamage@Eng.Sun.COM
  12. X-Auth: PGPMoose V1.1 PGP comp.std.c++
  13.     iQBFAgUBMVIPY+EDnX0m9pzZAQErnAF/fXUOB9kzkkUV+3xD+EyRFe170csYROxa
  14.     dDsK84Ht/96VwMWN+Sqi8r6/UE8AvrQu
  15.     =3mSj
  16.  
  17. In article RAA26760@florin.msk.su, "Dmitry M. Potapov" <dima@florin.msk.su>
  18. writes:
  19. >When bad_casting to pointer type, 
  20. >dynamic_cast<>() returns NULL.
  21. >
  22. >Is there a standard on good_casting,
  23. >I mean is it normal if dynamic_cast changes pointer,
  24. >and could dynamic_cast<>() be implemented w/o changing
  25. >the pointer if the cast was not bad ?
  26.  
  27. No cast changes a pointer. A cast yields a value based on an existing
  28. pointer value. The new value might be the same or different, but the
  29. original pointer is not changed.
  30.  
  31. Example, assuming each class has virtual functions:
  32.     class B1 { int i; ... };
  33.     class B2 { int j; ... }
  34.     class D : B1, B2 { int k; ... };
  35.  
  36. Given a D*, you can cast the value to either a B1* or a B2*. One of
  37. the results might be the same as the original, but they cannot both be
  38. the same.
  39.  
  40. Similarly, given a B1* and a B2*, you can cast either value to a D*.
  41. The result of one of the casts might be the same as the original value,
  42. but they cannot both be the same as the original. 
  43. ---
  44. Steve Clamage, stephen.clamage@eng.sun.com
  45. ---
  46. [ comp.std.c++ is moderated.  To submit articles: try just posting with      ]
  47. [ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu         ]
  48. [ FAQ:      http://reality.sgi.com/employees/austern_mti/std-c++/faq.html    ]
  49. [ Policy:   http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
  50. [ Comments? mailto:std-c++-request@ncar.ucar.edu                             ]
  51.